<?php

namespace app\admin\model;

use app\common\model\BaseModel;


class Company extends BaseModel
{

    

    

    // 表名
    protected $name = 'company';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'work_time_text',
        'is_market_text'
    ];
    

    
    public function getIsMarketList()
    {
        return ['0' => __('Is_market 0'), '1' => __('Is_market 1')];
    }


    public function getWorkTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['work_time']) ? $data['work_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getIsMarketTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_market']) ? $data['is_market'] : '');
        $list = $this->getIsMarketList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    protected function setWorkTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


}
